home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gplot3_2.lha / gnuplot / term / amiga.trm < prev    next >
Text File  |  1992-03-25  |  10KB  |  323 lines

  1. /*
  2.  * $Id: amiga.trm,v 3.26 92/03/24 22:34:45 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - amiga.trm */
  6. /*
  7.  * Copyright (C) 1991, 1992
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   Amiga Custom Screen
  25.  *
  26.  * AUTHORS
  27.  *   Carsten Steger
  28.  * 
  29.  *   Pat R. Empleo      Slightly modified for Aztec C v5.2a (beta); sort of
  30.  *   08/27/91           supports overscan; for large WB 2.0 virtual screens,
  31.  *                      we limit the plot size so we don't have to scroll
  32.  *                      around (not fun).
  33.  *
  34.  *   Carsten Steger     Modified to support Kickstart 2.0.
  35.  *   09/11/91           Opens a text overscan screen when used with WB 2.0.
  36.  *                      Discerns between NTSC and PAL Amigas when used with
  37.  *                      WB 1.3 and lower.
  38.  *
  39.  *   Pat R. Empleo      Defined some 2.0 stuff in order to get Aztec C to
  40.  *   09/20/91           work with Carsten's new code (see above).  When
  41.  *                      KS/WB 2.0 support gets implemented in Aztec C, this
  42.  *                      kludge will get deleted! 
  43.  *                      (Aztec C release 5.2 beta)
  44.  *
  45.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  46.  * 
  47.  */
  48.  
  49. #ifdef AMIGA_AC_5
  50. #include <intuition/intuitionbase.h>
  51. #include <intuition/screens.h>
  52. #include <graphics/text.h>
  53. #include <graphics/gfxbase.h>
  54. #else
  55. /* You will have to use the Kickstart 2.0 header files for this to compile */
  56. #include <exec/types.h>
  57. #include <intuition/intuitionbase.h>
  58. #include <graphics/gfxbase.h>
  59. #include <proto/intuition.h>
  60. #include <proto/graphics.h>
  61. #include <proto/exec.h>
  62. #include <proto/diskfont.h>
  63. #endif
  64.  
  65. extern char *getenv(),*strchr();
  66.  
  67. #define AMIGA_XMAX 640
  68. #define AMIGA_YMAX 512
  69.  
  70. #define AMIGA_VCHAR (12)
  71. #define AMIGA_HCHAR (8)
  72. #define AMIGA_VTIC (AMIGA_YMAX/80)
  73. #define AMIGA_HTIC (AMIGA_XMAX/80)
  74. /* The origin is in the upper left hand corner, so we have to translate */
  75. /* and flip the coordinates: */
  76. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  77.  
  78.  
  79. struct IntuitionBase *IntuitionBase;
  80. struct GfxBase *GfxBase;
  81. struct Library *DiskfontBase;
  82. static struct TextAttr AMIGA_Font = {
  83.   "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
  84. };
  85. static struct TextFont *AMIGA_TextFont;
  86. static struct NewScreen AMIGA_NewScreen = {
  87.   0,0,AMIGA_XMAX,AMIGA_YMAX,4,15,0,HIRES|LACE,
  88.   CUSTOMSCREEN|SCREENBEHIND|SCREENQUIET,NULL,NULL,NULL,NULL
  89. };
  90. static struct Screen *AMIGA_Screen;
  91. static UWORD AMIGA_Colors [] = {
  92.   0x000,0xfff,0xbbb,0x0f0,0xf00,0x00f,0x3ca,0xf0f,
  93.   0x94d,0x0ff,0x82f,0xff0,0x0af,0xc5e,0xfa2,0xf44
  94. };
  95. static int AMIGA_slinetype;
  96. static enum JUSTIFY AMIGA_justify = LEFT;
  97. static unsigned int AMIGA_ymax,AMIGA_xmax; 
  98. static WORD AMIGA_cwd,AMIGA_cht,AMIGA_bsl,AMIGA_vadj;
  99. static struct TagItem AMIGA_ScrTagList[] = {
  100.   {SA_Overscan,OSCAN_TEXT},{TAG_DONE,0}
  101. };
  102.  
  103.  
  104. AMIGA_reset()
  105. {
  106.   if (AMIGA_TextFont != NULL) CloseFont(AMIGA_TextFont);
  107.   if (DiskfontBase != NULL) CloseLibrary(DiskfontBase);
  108.   if (AMIGA_Screen != NULL) CloseScreen(AMIGA_Screen);
  109.   if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  110.   if (GfxBase != NULL) CloseLibrary(GfxBase);
  111.   AMIGA_TextFont = NULL;
  112.   DiskfontBase = NULL;
  113.   AMIGA_Screen = NULL;
  114.   IntuitionBase = NULL;
  115.   GfxBase = NULL;
  116. }
  117.  
  118.  
  119. AMIGA_init()
  120. {
  121.   static char fontname[80],*gnufont,*search;
  122.   static int fsize;
  123.   static char *test_str =
  124.     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  125.   static WORD test_len,test_pxl;
  126.  
  127.  
  128. #ifdef AMIGA_LC_5_1
  129.   /* Install exit trap in case of abnormal termination (see below). */
  130.   int AMIGA_exit();
  131.   if (!onexit(&AMIGA_exit)) {
  132.     fprintf(stderr,"Couldn't set exit trap\n");
  133.     exit(20);
  134.   }
  135. #endif
  136.   GfxBase = OpenLibrary("graphics.library",0);
  137.   if (GfxBase == NULL) {
  138.     fprintf(stderr,"No Graphics-Library\n");
  139.     AMIGA_reset();
  140.     exit(20);
  141.   }
  142.   IntuitionBase = OpenLibrary("intuition.library",0);
  143.   if (IntuitionBase == NULL) {
  144.     fprintf(stderr,"No Intuition-Library\n");
  145.     AMIGA_reset();
  146.     exit(20);
  147.   }
  148.   if (IntuitionBase->LibNode.lib_Version <= 34) {
  149.     /* We compute the vertical resolution for those poor NTSC-souls   :-)   */
  150.     if (GfxBase->DisplayFlags & PAL) AMIGA_ymax = 512;
  151.     else AMIGA_ymax = 400;
  152.     AMIGA_xmax = 640;
  153.     AMIGA_NewScreen.Width = AMIGA_xmax;
  154.     AMIGA_NewScreen.Height = AMIGA_ymax;
  155.     AMIGA_Screen = OpenScreen(&AMIGA_NewScreen);
  156.     if (AMIGA_Screen == NULL) {
  157.       fprintf(stderr,"No Screen\n");
  158.       AMIGA_reset();
  159.       exit(20);
  160.     }
  161.   } else {
  162.     /* Kickstart 2.0 support */
  163.     AMIGA_NewScreen.Width = STDSCREENWIDTH;
  164.     AMIGA_NewScreen.Height = STDSCREENHEIGHT;
  165.     AMIGA_Screen = OpenScreenTagList(&AMIGA_NewScreen,AMIGA_ScrTagList);
  166.     if (AMIGA_Screen == NULL) {
  167.       fprintf(stderr,"No Screen\n");
  168.       AMIGA_reset();
  169.       exit(20);
  170.     }
  171.     AMIGA_xmax = AMIGA_Screen->Width;
  172.     AMIGA_ymax = AMIGA_Screen->Height;
  173.   }
  174.   term_tbl[term].xmax = AMIGA_xmax;
  175.   term_tbl[term].ymax = AMIGA_ymax;
  176.   gnufont = getenv("GNUFONT");
  177.   if (gnufont != NULL ) {
  178.     search = strchr(gnufont,'/');
  179.     if (search != NULL) {
  180.       *search++ = '\0';
  181.       strncpy(fontname,gnufont,74);
  182.       strcat(fontname,".font");
  183.       sscanf(search,"%d",&fsize);
  184.       /* Avoid opening "diskfont.library" if a built-in font is desired */
  185.       if ((strcmp("topaz.font",fontname) == 0) &&
  186.         ((fsize == TOPAZ_EIGHTY) || (fsize == TOPAZ_SIXTY))) {
  187.         AMIGA_Font.ta_Name = fontname;
  188.         AMIGA_Font.ta_YSize = fsize;
  189.         AMIGA_Font.ta_Style = FS_NORMAL;
  190.         AMIGA_Font.ta_Flags = FPF_ROMFONT;
  191.         AMIGA_TextFont = OpenFont(&AMIGA_Font);
  192.         if (AMIGA_TextFont != NULL) 
  193.           SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  194.       } else {
  195.         DiskfontBase = OpenLibrary("diskfont.library",0);
  196.         if (DiskfontBase != NULL) {
  197.           AMIGA_Font.ta_Name = fontname;
  198.           AMIGA_Font.ta_YSize = fsize;
  199.           AMIGA_Font.ta_Style = FS_NORMAL;
  200.           AMIGA_Font.ta_Flags = FPF_ROMFONT|FPF_DISKFONT;
  201.           AMIGA_TextFont = OpenDiskFont(&AMIGA_Font);
  202.           if (AMIGA_TextFont != NULL)
  203.             SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  204.         }
  205.       }
  206.     }
  207.   }
  208.   /* Width of characters: This works better for proportional fonts than */
  209.   /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
  210.   test_len = strlen(test_str);
  211.   test_pxl = TextLength(&AMIGA_Screen->RastPort,test_str,test_len);
  212.   AMIGA_cwd = test_pxl / test_len;
  213.   AMIGA_cht = AMIGA_Screen->RastPort.TxHeight; /* Height of characters */
  214.   AMIGA_bsl = AMIGA_Screen->RastPort.TxBaseline; /* Reference line */
  215.   /* Amount by which characters have to be shifted upwards to be */
  216.   /* vertically justified: */
  217.   AMIGA_vadj = AMIGA_bsl / 2;
  218.   term_tbl[term].v_char = AMIGA_cht + 4; /* So lines won't be too close */
  219.   term_tbl[term].h_char = AMIGA_cwd;
  220.   LoadRGB4(&AMIGA_Screen->ViewPort,AMIGA_Colors,16);
  221.   RemakeDisplay();
  222.   AMIGA_slinetype = 1;
  223.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  224.   SetDrMd(&AMIGA_Screen->RastPort,JAM1);
  225. }
  226.  
  227.  
  228. AMIGA_text()
  229. {
  230.   char c;
  231.  
  232.   c = getc(stdin); /* This is extremely ugly... Yuk !!!!   >:-(   */
  233.   ungetc(c,stdin); /* Maybe someone else will find a better solution */
  234.   ScreenToBack(AMIGA_Screen);
  235. }
  236.  
  237.  
  238. AMIGA_graphics()
  239. {
  240.   SetRast(&AMIGA_Screen->RastPort,0);
  241.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  242.   ScreenToFront(AMIGA_Screen);
  243. }
  244.  
  245.  
  246. AMIGA_move(x,y)
  247. unsigned int x,y;
  248. {
  249.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  250.   Move(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  251. }
  252.  
  253.  
  254. AMIGA_vector(x,y)
  255. unsigned int x,y;
  256. {
  257.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  258.   Draw(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  259. }
  260.  
  261.  
  262. AMIGA_linetype(linetype)
  263. int linetype;
  264. {
  265.   if (linetype >= 13) linetype %= 13;
  266.   AMIGA_slinetype = linetype+3;
  267.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  268. }
  269.  
  270.  
  271. AMIGA_put_text(x,y,str)
  272. unsigned int x,y;
  273. char *str;
  274. {
  275.   LONG len,tx_len;
  276.   WORD xmin,xmax,ymin,ymax;
  277.  
  278.   len = strlen(str);
  279.   tx_len = TextLength(&AMIGA_Screen->RastPort,str,len);
  280.   switch (AMIGA_justify) {
  281.     case LEFT:
  282.       xmin = x;
  283.       xmax = x + tx_len;
  284.       break;
  285.     case CENTRE:
  286.       xmin = x - tx_len / 2;
  287.       xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  288.       break;
  289.     case RIGHT:
  290.       xmin = x - tx_len;
  291.       xmax = x;
  292.       break;
  293.   }
  294.   ymin = AMIGA_VTF(y) - AMIGA_vadj;
  295.   ymax = ymin + AMIGA_cht;
  296.   /* Check if character-string lies completely within the screen: */
  297.   if ((xmax >= AMIGA_xmax) || (ymin < 0) || (ymax >= AMIGA_ymax)) return;
  298.   Move(&AMIGA_Screen->RastPort,xmin,ymin+AMIGA_bsl);
  299.   Text(&AMIGA_Screen->RastPort,str,len);
  300. }
  301.  
  302.  
  303. int AMIGA_justify_text(mode)
  304. enum JUSTIFY mode;
  305. {
  306.   AMIGA_justify = mode;
  307.   return TRUE;
  308. }
  309.  
  310.  
  311. /* This function is mainly included if the program terminates abnormally */
  312. /* and the screen and libraries are still open. It closes down all opened */
  313. /* libraries and screens. This happens e.g. when loading "bivariat.demo" */
  314. /* and the stack is smaller than 70000 bytes. */
  315. #ifdef AMIGA_LC_5_1
  316. int AMIGA_exit(rc)
  317. int rc;
  318. {
  319.   AMIGA_reset();
  320.   return rc;
  321. }
  322. #endif
  323.